package com.jushu.storbox.entities;

import android.content.ContentValues;
import android.database.Cursor;

import com.jushu.storbox.ShareDriveApplication;
import com.jushu.storbox.database.IBaseDao;
import com.jushu.storbox.database.IObjectConvert;
import com.jushu.storbox.database.UploadFileDao;
import com.jushu.storbox.task.tqueue.UploadTask;
import com.jushu.storbox.util.PublicTools;

public class UploadObject extends ResourceEntity implements IObjectConvert{

	/** */
	private static final long serialVersionUID = -4385073696824145238L;
	
	private String name;
	private String parent;
	private String identity;
	private String extendIdentity;
	private int transStatus;
	private long currentPaogress;
	private String currentSize;
	private long size;
	private String loctPath;
	private String uploadPath;
	private long setLastUpdateDate;
	private String currentIndex;
	private int type;
	private int notifyId;
	private String currentUserId = null;

	private transient UploadTask uploadTask = null;
	
	public String getCurrentUserId() {
		return currentUserId;
	}
	public void setCurrentUserId(String currentUserId) {
		this.currentUserId = currentUserId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getParent() {
		return parent;
	}
	public void setParent(String parent) {
		this.parent = parent;
	}
	public int getTransStatus() {
		return transStatus;
	}
	public void setTransStatus(int transStatus) {
		this.transStatus = transStatus;
	}
	public long getCurrentPaogress() {
		return currentPaogress;
	}
	public void setCurrentPaogress(long currentPaogress) {
		this.currentPaogress = currentPaogress;
	}
	public String getCurrentSize() {
		return currentSize;
	}
	public void setCurrentSize(String currentSize) {
		this.currentSize = currentSize;
	}
	public long getSize() {
		return size;
	}
	public void setSize(long size) {
		this.size = size;
	}
	public String getLoctPath() {
		return loctPath;
	}
	public void setLoctPath(String loctPath) {
		this.loctPath = loctPath;
	}
	public String getUploadPath() {
		return uploadPath;
	}
	public void setUploadPath(String uploadPath) {
		this.uploadPath = uploadPath;
	}
	public long getSetLastUpdateDate() {
		return setLastUpdateDate;
	}
	public void setSetLastUpdateDate(long setLastUpdateDate) {
		this.setLastUpdateDate = setLastUpdateDate;
	}
	public String getCurrentIndex() {
		return currentIndex;
	}
	public void setCurrentIndex(String currentIndex) {
		this.currentIndex = currentIndex;
	}
	
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public int getNotifyId() {
		return notifyId;
	}
	public void setNotifyId(int notifyId) {
		this.notifyId = notifyId;
	}
	@Override
	public String toString() {
		return "UploadObject [id=" + id + ", name=" + name + ", parent="
				+ parent + ", OwnerBy=" + ownerBy + ", identity=" + identity
				+ ", transStatus=" + transStatus + ", currentPaogress="
				+ currentPaogress + ", currentSize=" + currentSize + ", size="
				+ size + ", loctPath=" + loctPath + ", uploadPath="
				+ uploadPath + ", setLastUpdateDate=" + setLastUpdateDate
				+ ", currentIndex=" + currentIndex + "]";
	}
	public String getIdentity() {
		return identity;
	}
	public void setIdentity(String identity) {
		this.identity = identity;
	}
	
	public String getExtendIdentity() {
		return extendIdentity;
	}
	public void setExtendIdentity(String extendIdentity) {
		this.extendIdentity = extendIdentity;
	}
	public UploadTask getUploadTask() {
		return uploadTask;
	}
	public void setUploadTask(UploadTask uploadTask) {
		this.uploadTask = uploadTask;
	}
	public void fromCursor(Cursor cursor) {
		setId(cursor.getString(cursor.getColumnIndex(IBaseDao.id)));
		setName(cursor.getString(cursor.getColumnIndex(IBaseDao.file_name)));
		setOwnerBy(cursor.getString(cursor.getColumnIndex(IBaseDao.owner_by)));
		setIdentity(cursor.getString(cursor.getColumnIndex(IBaseDao.file_sha1)));
		setParent(cursor.getString(cursor.getColumnIndex(IBaseDao.parent_folder_id)));
		setTransStatus(cursor.getInt(cursor.getColumnIndex(IBaseDao.trans_status)));
		setCurrentPaogress(cursor.getLong(cursor.getColumnIndex(IBaseDao.current_progress)));
		setCurrentSize(cursor.getString(cursor.getColumnIndex(IBaseDao.current_size)));
		setCurrentIndex(cursor.getString(cursor.getColumnIndex(IBaseDao.current_index)));
		setSize(cursor.getLong(cursor.getColumnIndex(IBaseDao.file_size)));
		setLoctPath(cursor.getString(cursor.getColumnIndex(IBaseDao.local_path)));
		setUploadPath(cursor.getString(cursor.getColumnIndex(IBaseDao.upload_path)));
		setSetLastUpdateDate(cursor.getLong(cursor.getColumnIndex(IBaseDao.lastUpdateDate)));
		setType(cursor.getInt(cursor.getColumnIndex(IBaseDao.type)));
		setExtendIdentity(cursor.getString(cursor.getColumnIndex(IBaseDao.extend_identity)));
		setNotifyId(cursor.getInt(cursor.getColumnIndex(IBaseDao.notify_id)));
		setCurrentUserId(cursor.getString(cursor.getColumnIndex(UploadFileDao.current_user_id)));
	}
	
	public ContentValues toContentValues() {
		ContentValues cv = new ContentValues();
		cv.put(IBaseDao.id, getId());
		cv.put(IBaseDao.file_name, getName());
		cv.put(IBaseDao.owner_by, getOwnerBy());
		cv.put(IBaseDao.file_sha1, getIdentity());
		cv.put(IBaseDao.extend_identity, getExtendIdentity());
		cv.put(IBaseDao.notify_id, getNotifyId());
		cv.put(IBaseDao.parent_folder_id, getParent());
		cv.put(IBaseDao.trans_status, getTransStatus());    
		cv.put(IBaseDao.current_progress, getCurrentPaogress());
		cv.put(IBaseDao.current_index,getCurrentIndex());     
		cv.put(IBaseDao.current_size,getCurrentSize());     
		cv.put(IBaseDao.file_size, getSize());  
		cv.put(IBaseDao.local_path, getLoctPath()); 
		cv.put(IBaseDao.upload_path, getUploadPath());
		cv.put(IBaseDao.lastUpdateDate, PublicTools.getCurrentTime());
		cv.put(IBaseDao.type, getType());
		cv.put(UploadFileDao.current_user_id, ShareDriveApplication.getInstance().getWnerID());
		return cv;
	}
}
